#include <iostream>
#include <ctime>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>

// 新线程
void *threadStart(void *args)
{
    while (true)
    {
        std::cout << "new thread running..." << ", pid: " << getpid() << std::endl;
        sleep(1);
        int x = rand() % 50;
        if (x == 0)
        {
            int *p = nullptr;
            *p = 100;
        }
        
    }
}

int main()
{
    srand(time(nullptr));
    pthread_t tid1;
    pthread_create(&tid1, nullptr, threadStart, (void *)"thread-new");

    pthread_t tid2;
    pthread_create(&tid2, nullptr, threadStart, (void *)"thread-new");

    pthread_t tid3;
    pthread_create(&tid3, nullptr, threadStart, (void *)"thread-new");

    // 主线程
    while (true)
    {
        sleep(1);
        std::cout << "main thread running..." << ", pid: " << getpid() << std::endl;
    }

    return 0;
}
